package wec_wallet.ebo.com.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

import bassproject.ebo.com.ebobass.activity.MyBaseActivity;
import bassproject.ebo.com.ebobass.utils.CacheUtility;
import wec_wallet.ebo.com.common.Constants;

import bassproject.ebo.com.ebobass.utils.I_Share;
import wec_wallet.ebo.com.R;
import wec_wallet.ebo.com.utils.Functions;
import wec_wallet.ebo.com.widget.ColorArcProgressBar;
import wec_wallet.ebo.com.widget.EaseSwitchButton;

public class SafetyTestActivity extends MyBaseActivity {

    private EaseSwitchButton safety_switch_btn;
    private Button safety_btn_start;
    private ColorArcProgressBar ramclean_progress_bar;
    private TextView safety_switch_text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_safety_test);
        initViews();
    }

    @Override
    public void initViews() {
        safety_switch_btn = (EaseSwitchButton) findViewById(R.id.safety_switch_btn);
        safety_switch_btn.setOnClickListener(this);
        safety_btn_start = (Button) findViewById(R.id.safety_btn_start);
        safety_btn_start.setOnClickListener(this);
        ramclean_progress_bar = (ColorArcProgressBar) findViewById(R.id.ramclean_progress_bar);
        safety_switch_text = (TextView) findViewById(R.id.safety_switch_text);
        findViewById(R.id.actionbar_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        boolean b = CacheUtility.spGetOut(this, Constants.SAFETY_OPEN+I_Share.readAccountUserid(), false);
        if (!b){
            safety_switch_btn.closeSwitch();
            safety_switch_text.setText(getString(R.string.switch_close));
        }else {
            safety_switch_btn.openSwitch();
            safety_switch_text.setText(getString(R.string.switch_open));
        }
    }

    @Override
    public void onClick(View v) {
    switch (v.getId()){
        case R.id.safety_switch_btn:
            toggleBlockGroup();
            break;
            case R.id.safety_btn_start:
                Random random = new Random();
                int i = random.nextInt(100);
                ramclean_progress_bar.setCurrentValues(100 );
            break;

    }
    }
    private void toggleBlockGroup() {
        if (safety_switch_btn.isSwitchOpen()) {
            safety_switch_btn.closeSwitch();
            safety_switch_text.setText(getString(R.string.switch_close));
            if (I_Share.isLogin()){
                CacheUtility.spSave(this, Constants.SAFETY_OPEN+I_Share.readAccountUserid(),false);
            }else {
                Functions.relogin(this);
            }

        } else {
            safety_switch_btn.openSwitch();
            safety_switch_text.setText(getString(R.string.switch_open));
            if (I_Share.isLogin()){
            CacheUtility.spSave(this, Constants.SAFETY_OPEN+I_Share.readAccountUserid(),true);
            }else {
                Functions.relogin(this);
            }

        }
    }
}
